package com.bhs.sansonglogistics.ui.adapter;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.PictureShowBean;
import com.bhs.sansonglogistics.utils.LogUtils;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class PictureShowAdapter2 extends BaseQuickAdapter<Object, BaseViewHolder> {

    private int size;

    public PictureShowAdapter2(@Nullable List<Object> data, int size) {
        super(R.layout.item_picture4, data);
        this.size = size;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, Object item) {
        ImageView mImageView = helper.getView(R.id.iv_picture);
        if (size == 1) {
            mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
            Glide.with(mContext)
                    .asBitmap()
                    .load(MyUtils.watermark((String) item))
                    .into(new CustomTarget<Bitmap>(400, 400) {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                            ViewGroup.LayoutParams layoutParams = mImageView.getLayoutParams();
                            if (resource.getWidth() > resource.getHeight()) {
                                layoutParams.height = 400;
                            } else if (resource.getWidth() == resource.getHeight()) {
                                layoutParams.width = 400;
                                layoutParams.height = 400;
                            } else {
                                layoutParams.width = 400;
                            }
                            mImageView.setLayoutParams(layoutParams);
                            mImageView.setImageBitmap(resource);
                        }

                        @Override
                        public void onLoadCleared(@Nullable Drawable placeholder) {

                        }
                    });
        } else {
            Glide.with(mContext).load(MyUtils.watermark((String) item)).into(mImageView);
            ViewGroup.LayoutParams layoutParams = mImageView.getLayoutParams();
            if (size == 2 || size == 4) {
                layoutParams.width = 350;
                layoutParams.height = 350;
            } else {
                layoutParams.width = 280;
                layoutParams.height = 280;
            }

            mImageView.setLayoutParams(layoutParams);
        }


    }
}
